{{include file="public/header.php"/}}

<ol class="breadcrumb">
	<li>
		<span class="glyphicon glyphicon-home"></span>
		<a href="{{U('Cms/Index/index')}}">首页</a>
	</li>
	<li>菜单列表</li>
</ol>

<div id="page-wrapper">
	<div class="row">
		<div class="col-lg-12">
			<div class="alert alert-success" style="border:solid 1px #27ae60;">
				只有三级菜单需要设置模块/控制器/方法
			</div>
		</div>
	</div>
	<div class="row">
		<div class="col-lg-12">
			<div class="main-box">
				<header class="main-box-header clearfix">
					<h2>编辑菜单</h2>
				</header>
				<div class="main-box-body clearfix">
					<form role="form" onsubmit="return update({{$field['id']}});">
						<input type="hidden" name="id" value="{{$field['id']}}">
						<input type="hidden" name="_method" value="PUT">
						<div class="form-group">
							<label for="pid">上级</label>
							<select name="pid" id="pid" class="form-control">
								<option value="0">一级菜单</option>
								{{foreach value="$v" key="$k" from="$menu"}}
								<option value="{{$v['id']}}"
								{{if value="Api('Menu/isChildMenu',array($v['id'],$field['id'])) || $field['id']==$v['id']"}}
									disabled=""
								{{/if}}

								{{if value="$field['pid']==$v['id']"}}
									selected=""
								{{/if}}
								>
								{{$v['_name']}}
								</option>
								{{/foreach}}
							</select>
						</div>
						<div class="form-group">
							<label for="title">菜单名称</label>
							<input type="text" name="title" value="{{$field['title']}}" class="form-control" id="title">
						</div>
						<div class="form-group">
							<label for="module">模块</label>
							<input type="text" name="module" value="{{$field['module']}}" class="form-control" id="module">
						</div>
						<div class="form-group">
							<label for="controller">控制器</label>
							<input type="text" name="controller" value="{{$field['controller']}}" class="form-control" id="controller">
						</div>
						<div class="form-group">
							<label for="action">动作</label>
							<input type="text" name="action" value="{{$field['action']}}" class="form-control" id="action">
						</div>
						<div class="form-group">
							<label for="url">URL</label>
							<input type="text" name="url" value="{{$field['url']}}" class="form-control" id="url">
						</div>
						<div class="form-group">
							<label for="sort">排序</label>
							<input type="text" name="sort" value="{{$field['sort']}}" class="form-control" id="sort">
						</div>

						<div class="form-group">
							<label>系统菜单</label>

							<div class="radio">
								<input type="radio" name="system" id="system1" value="1"
								{{if value="$field['system']"}}checked{{/if}}>
								<label for="system1">
									是
								</label>
							</div>
							<div class="radio">
								<input type="radio" name="system" id="system2" value="0"
								{{if value="!$field['system']"}}checked{{/if}}>
								<label for="system2">
									不是
								</label>
							</div>
						</div>
						<div>
							<button type="submit" class="btn btn-primary btn-lg">
								修改菜单
							</button>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>

{{include file="public/footer.php"/}}
<script>
	//删除菜单
	function update(id) {
		$.ajax({
			url: "/cms/menu/"+id,
			data: $('form').serialize(),
			type: 'PUT',
			dataType: 'JSON',
			success: function (result) {
				if (result.code == 0) {
					dialog(result.message, 'success', 1000, function () {
						location.href = "/cms/menu"
					});
				}
				else {
					dialog(result.message, 'error', 1000);
				}
			}
		})
		return false;
	}
</script>